package com.ssm.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.InvitationEntityMapper;
import com.ssm.entity.EnterpriseEntity;
import com.ssm.entity.InvitationEntity;
import com.ssm.entity.RecruitEntity;
import com.ssm.service.InvitationService;
@Service("InvitationServiceImpl")
@Transactional
public class InvitationServiceImpl implements InvitationService{
	@Autowired
	private InvitationEntityMapper mapper;
	@Override
	public void save(InvitationEntity invitation) {
		mapper.insert(invitation);
		return;
	}

	@Override
	public boolean update(InvitationEntity invitation) {
		try {
			int result = mapper.updateByPrimaryKeySelective(invitation);
			System.out.print(result);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public List<InvitationEntity> findWithPage(Integer page, Integer pageNum) {
		if (page == null || pageNum == null) {
			return new ArrayList<InvitationEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<InvitationEntity> invitations= mapper.findAll();
				return invitations;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}

	@Override
	public List<InvitationEntity> findWithPageByStudent(String stuId, Integer page, Integer pageNum) {
		if (page == null || pageNum == null) {
			return new ArrayList<InvitationEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<InvitationEntity> invitations= mapper.findAllByStudent(stuId);
				return invitations;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}

	@Override
	public List<InvitationEntity> findWithPageByCompany(String companyId, Integer page, Integer pageNum) {
		if (page == null || pageNum == null) {
			return new ArrayList<InvitationEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<InvitationEntity> invitations= mapper.findAllByCompany(companyId);
				return invitations;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}
	
}
